/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * File Name          : freertos.c
  * Description        : Code for freertos applications
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2023 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* USER CODE END Header */

/* Includes ------------------------------------------------------------------*/
#include "FreeRTOS.h"
#include "task.h"
#include "main.h"
#include "cmsis_os.h"
#include "appTask.h"


/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */

/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN Variables */

/* USER CODE END Variables */
                                    //Task
/* Definitions for mainTask */
osThreadId_t mainTaskHandle;
const osThreadAttr_t mainTask_attributes = {
  .name = "mainTask",
  .stack_size = 128 * 4,
  .priority = (osPriority_t) osPriorityNormal,
};
/* Definitions for encoderTask */
osThreadId_t encoderTaskHandle;
const osThreadAttr_t encoderTask_attributes = {
  .name = "encoderTask",
  .stack_size = 128 * 4,
  .priority = (osPriority_t) osPriorityNormal1,
};
/* Definitions for guiTask */
osThreadId_t guiTaskHandle;
const osThreadAttr_t guiTask_attributes = {
  .name = "guiTask",
  .stack_size = 128 * 4,
  .priority = (osPriority_t) osPriorityLow,
};
                                    //Queue
/* Definitions for Encoder_Queue */
osMessageQueueId_t Encoder_QueueHandle;
const osMessageQueueAttr_t Encoder_Queue_attributes = {
  .name = "Encoder_Queue"
};
                                    //Timer
/* Definitions for myTimer01 */
osTimerId_t myTimer01Handle;
const osTimerAttr_t myTimer01_attributes = {
  .name = "myTimer01"
};
/* Definitions for myTimer02 */
osTimerId_t myTimer02Handle;
const osTimerAttr_t myTimer02_attributes = {
  .name = "myTimer02"
};
                                    //Mutex
/* Definitions for myMutex01 */
osMutexId_t f_Disp_MutexHandle;
const osMutexAttr_t f_Disp_Mutex_attributes = {
  .name = "f_Disp_Mutex",
	.attr_bits = osMutexPrioInherit
};
/* Definitions for myMutex02 */
osMutexId_t myMutex02Handle;
const osMutexAttr_t myMutex02_attributes = {
  .name = "myMutex02"
};
/* Definitions for myMutex03 */
osMutexId_t myMutex03Handle;
const osMutexAttr_t myMutex03_attributes = {
  .name = "myMutex03"
};
/* Definitions for myMutex04 */
osMutexId_t myMutex04Handle;
const osMutexAttr_t myMutex04_attributes = {
  .name = "myMutex04"
};
/* Definitions for myMutex05 */
osMutexId_t myMutex05Handle;
const osMutexAttr_t myMutex05_attributes = {
  .name = "myMutex05"
};
/* Definitions for myMutex06 */
osMutexId_t myMutex06Handle;
const osMutexAttr_t myMutex06_attributes = {
  .name = "myMutex06"
};
/* Definitions for myMutex07 */
osMutexId_t myMutex07Handle;
const osMutexAttr_t myMutex07_attributes = {
  .name = "myMutex07"
};

/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN FunctionPrototypes */

/* USER CODE END FunctionPrototypes */

void MainTaskFun(void *argument);
void EncoderTaskFun(void *argument);
void GuiTaskFun(void *argument);
void Timer1_Callback(void *argument);
void Timer2_Callback(void *argument);

void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */

/* Hook prototypes */
void configureTimerForRunTimeStats(void);
unsigned long getRunTimeCounterValue(void);

/* USER CODE BEGIN 1 */
/* Functions needed when configGENERATE_RUN_TIME_STATS is on */
__weak void configureTimerForRunTimeStats(void)
{

}

__weak unsigned long getRunTimeCounterValue(void)
{
return 0;
}
/* USER CODE END 1 */

/**
  * @brief  FreeRTOS initialization
  * @param  None
  * @retval None
  */
void MX_FREERTOS_Init(void) {
  /* USER CODE BEGIN Init */

  /* USER CODE END Init */
  /* Create the mutex(es) */
  /* creation of myMutex01 */
  f_Disp_MutexHandle = osMutexNew(&f_Disp_Mutex_attributes);

  /* creation of myMutex02 */
  myMutex02Handle = osMutexNew(&myMutex02_attributes);

  /* creation of myMutex03 */
  myMutex03Handle = osMutexNew(&myMutex03_attributes);

  /* creation of myMutex04 */
  myMutex04Handle = osMutexNew(&myMutex04_attributes);

  /* creation of myMutex05 */
  myMutex05Handle = osMutexNew(&myMutex05_attributes);

  /* creation of myMutex06 */
  myMutex06Handle = osMutexNew(&myMutex06_attributes);

  /* creation of myMutex07 */
  myMutex07Handle = osMutexNew(&myMutex07_attributes);

  /* USER CODE BEGIN RTOS_MUTEX */
  /* add mutexes, ... */
  /* USER CODE END RTOS_MUTEX */

  /* USER CODE BEGIN RTOS_SEMAPHORES */
  /* add semaphores, ... */
  /* USER CODE END RTOS_SEMAPHORES */

  /* Create the timer(s) */
  /* creation of myTimer01 */
  myTimer01Handle = osTimerNew(Timer1_Callback, osTimerPeriodic, NULL, &myTimer01_attributes);

  /* creation of myTimer02 */
  myTimer02Handle = osTimerNew(Timer2_Callback, osTimerOnce, NULL, &myTimer02_attributes);

  /* USER CODE BEGIN RTOS_TIMERS */
  /* start timers, add new ones, ... */
  /* USER CODE END RTOS_TIMERS */

  /* Create the queue(s) */
  /* creation of Encoder_Queue */
  Encoder_QueueHandle = osMessageQueueNew (20, sizeof(uint8_t), &Encoder_Queue_attributes);

  /* USER CODE BEGIN RTOS_QUEUES */
  /* add queues, ... */
  /* USER CODE END RTOS_QUEUES */

  /* Create the thread(s) */
	
  /* creation of mainTask */
  mainTaskHandle = osThreadNew(MainTaskFun, NULL, &mainTask_attributes);

  /* creation of encoderTask */
  encoderTaskHandle = osThreadNew(EncoderTaskFun, NULL, &encoderTask_attributes);

  /* creation of guiTask */
  guiTaskHandle = osThreadNew(GuiTaskFun, NULL, &guiTask_attributes);

  /* USER CODE BEGIN RTOS_THREADS */
  /* add threads, ... */
  /* USER CODE END RTOS_THREADS */

  /* USER CODE BEGIN RTOS_EVENTS */
  /* add events, ... */
  /* USER CODE END RTOS_EVENTS */

}

/* USER CODE BEGIN Header_MainTaskFun */
/**
  * @brief  Function implementing the mainTask thread.
  * @param  argument: Not used
  * @retval None
  */
/* USER CODE END Header_MainTaskFun */
__weak void MainTaskFun(void *argument)
{
  /* USER CODE BEGIN MainTaskFun */
  /* Infinite loop */
  for(;;)
  {
    osDelay(1);
  }
  /* USER CODE END MainTaskFun */
}

/* USER CODE BEGIN Header_EncoderTaskFun */
/**
* @brief Function implementing the encoderTask thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_EncoderTaskFun */
__weak void EncoderTaskFun(void *argument)
{
  /* USER CODE BEGIN EncoderTaskFun */
  /* Infinite loop */
  for(;;)
  {
    osDelay(1);
  }
  /* USER CODE END EncoderTaskFun */
}

/* USER CODE BEGIN Header_GuiTaskFun */
/**
* @brief Function implementing the guiTask thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_GuiTaskFun */
__weak void GuiTaskFun(void *argument)
{
  /* USER CODE BEGIN GuiTaskFun */
  /* Infinite loop */
  for(;;)
  {
    osDelay(1);
  }
  /* USER CODE END GuiTaskFun */
}

/* Timer1_Callback function */
void Timer1_Callback(void *argument)
{
  /* USER CODE BEGIN Timer1_Callback */

  /* USER CODE END Timer1_Callback */
}

/* Timer2_Callback function */
void Timer2_Callback(void *argument)
{
  /* USER CODE BEGIN Timer2_Callback */

  /* USER CODE END Timer2_Callback */
}

/* Private application code --------------------------------------------------*/
/* USER CODE BEGIN Application */

/* USER CODE END Application */

